package com.zhupf.doublePoint;

/**
 * @author zhupf
 * @date 2023年10月25日 11:15
 * @Description
 */
public class MaxArea {
    public static void main(String[] args) {
        int[] height = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(height));

    }
    
    public static int maxArea(int[] height) {
        int idx_left = 0;
        int idx_right = height.length-1;
        int max = 0;
        while (idx_left<idx_right){
            int area = Math.min(height[idx_right],height[idx_left])*(idx_right-idx_left);
            max = Math.max(max,area);
            if(height[idx_left] <  height[idx_right]){
                idx_left ++;
            }else {
                idx_right--;
            }
        }
        return max;
    }
}
